package com.yiduan.apollocrm.views.mediators
{
	import com.yiduan.apollocrm.models.Product;
	import com.yiduan.apollocrm.views.NewOrEditProductView;
	import com.yiduan.apollocrm.views.ProductsView;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.resources.ResourceManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class ProductsMediator extends Mediator
	{
		[Inject]
		public var productsView:ProductsView;		
		
		public function ProductsMediator() {
			super();
		}
		
		override public function onRegister():void {
			getProductList();
			productsView.newProductBtn.addEventListener(MouseEvent.CLICK, newProductHandler);
		}
		
		private function newProductHandler(e:Event):void {
			productsView.navigator.pushView(NewOrEditProductView);
		}
		
		private function getProductList():void {
			var productCollection:ArrayCollection = new ArrayCollection();
			var product1:Product = new Product();
			product1.name = "产品1";
			product1.description = "描述1";
			productCollection.addItem(product1);
			var product2:Product = new Product();
			product2.name = "产品2";
			product2.description = "描述2";
			productCollection.addItem(product2);
			var product3:Product = new Product();
			product3.name = "产品3";
			product3.description = "描述3";
			productCollection.addItem(product3);
			var product4:Product = new Product();
			product4.name = "产品4";
			product4.description = "描述4";
			productCollection.addItem(product4);
			var product5:Product = new Product();
			product5.name = "产品5";
			product5.description = "描述5";
			productCollection.addItem(product5);
			productsView.productList.dataProvider = productCollection;
		}

	}
}